import './App.less';
import { ConfigProvider } from 'antd';
import { useRecoilState } from 'recoil';
import { appStore, appUserStore } from './App.store.ts';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { useMemo } from 'react';
import Application from './application';
import { permission } from 'src/utils/define-route-config';

function App() {
  const [state] = useRecoilState(appStore);
  const [appUser] = useRecoilState(appUserStore);
  const router = useMemo(
    () => createBrowserRouter(permission(Application, appUser?.authorities)),
    [appUser?.authorities],
  );
  return (
    <>
      <ConfigProvider
        locale={state.locales.find((o) => o.code === state.language)?.antd}
      >
        <RouterProvider router={router} />
      </ConfigProvider>
    </>
  );
}

export default App;
